package com.btm.easymetadata.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.btm.easymetadata.server.entity.dto.DataFieldDTO;
import com.btm.easymetadata.server.entity.base.Response;
import com.btm.easymetadata.server.entity.vo.DataFieldVO;
import com.btm.easymetadata.server.service.DataFieldService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@AllArgsConstructor
@RestController
@RequestMapping("/data_field")
public class DataFieldController {

    private final DataFieldService dataFieldService;


    @PostMapping("/add")
    public Response<Boolean> addDataField(@RequestBody DataFieldDTO dataFieldDTO) {
        Response<Boolean> booleanResponse = new Response<>();
        booleanResponse.setCode(200);
        booleanResponse.setData(dataFieldService.add(dataFieldDTO));
        return booleanResponse;
    }

    @PostMapping("/update")
    public Response<Boolean> updateDataField(@RequestBody DataFieldDTO dataFieldDTO) {
        Response<Boolean> booleanResponse = new Response<>();
        booleanResponse.setCode(200);
        booleanResponse.setData(dataFieldService.update(dataFieldDTO));
        return booleanResponse;
    }

    @PostMapping("/list")
    public Response<IPage<DataFieldVO>> list(@RequestBody DataFieldDTO dataFieldDTO) {
        Response<IPage<DataFieldVO>> response = new Response<>();
        response.setCode(200);
        response.setData(dataFieldService.list(dataFieldDTO));
        return response;
    }
}
